<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="common" uri="/common.tag" %>

<link rel="stylesheet" href="./jquery/jquery-ui-1.8.18.custom/development-bundle/themes/base/jquery.ui.all.css">
    <script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/jquery-1.7.1.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/external/jquery.bgiframe-2.1.2.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.ui.core.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.ui.widget.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.ui.mouse.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.ui.draggable.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.ui.position.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.ui.resizable.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.ui.dialog.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.effects.core.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.effects.blind.js"></script>
	<script src="./jquery/jquery-ui-1.8.18.custom/development-bundle/ui/jquery.effects.explode.js"></script>
    <script src = "js/My97DatePicker/WdatePicker.js" defer = "defer"></script>
<script type="text/javascript" src="./jspfckeditor/fckeditor.js"></script>
<link rel="stylesheet" href="jquery/jquery-ui-1.8.18.custom/development-bundle/demos/demos.css"/>
<script src="./jquery/jquery.blockUI.js"></script>
<script src="./jquery/SimpleBox.js"></script>
<script src="./js/jquery.bub.js"></script>

<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
  <script type="text/javascript" src="ext/ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css"/>
<label id="errorMsg" style="display: none"><common:national key="common.system.exception"></common:national></label>
<input type='hidden' id='disSplitPage' value='1'/>
<input type='hidden' id='disSplitPage2' value='1'/>


<script type="text/javascript" src="js/jquery.splitPage.anler.js"></script>
<script type="text/javascript" src="js/page.split.js"></script>

<link rel="stylesheet" src="css/comm.css"/>
<style>
.x-grid3-hd-btn{
   color: red
}
/* Override standard grid styles (add colour to vertical grid lines) */   
.x-grid3-col {   
    border-left:  1px solid #EEEEEE;   
    border-right: 1px solid #D2D2D2;
    border-bottom:  1px solid #EEEEEE;   
    border-top: 1px solid #D2D2D2; 
    text-align: center;
}   
    
/* Also remove padding from table data (to compensate for added grid lines) */   
.x-grid3-row td, .x-grid3-summary-row td {   
    padding-left: 0px;   
    padding-right: 0px;   
}  


.pagelist{float:left;width:100%;padding-top:20px;}
.pagelist ul{text-align:center;line-height:50px;}
.pagelist ul a{
	margin-right:10px;
	font-size:12px;
	padding:5px 10px 5px 10px;	
	border: 1px solid #D5D5D5;
	line-height:26px;
	height:26px;
	color: #333;
	background-color: #FFF;
	cursor: pointer;
}
.pagelist ul a.current{
	border: 1px solid #FF9E20;
	background-color: #FF9000;
	font-weight: bold;
	color: #FFF;
}
.pagelist ul span{font-size:14px;}
.pagelist ul a span{}

.increaseOrReduce{
  cursor: pointer;
  
}

.deleteOperation{
  cursor: pointer;
}

</style>

<script type="text/javascript" >

  //将指定的网页加载到指定元素里面
  function loadPage(sourceId,pageUrl,callBack){
    $(sorceId).html("test112");
  }
  
   //用来向目标对象加载指定url的文件
  function load(sourceId,url,cache,callBack){
    block();
    var sourceObj = $("#" + sourceId) || $(sourceId);
    if(!cache){
       //需要缓存，关闭ajax缓存
       $.ajaxSetup({
         cache: false
       });
    }else{
       $.ajaxSetup({
         cache: true
       })
    }
    sourceObj.html("");
    sourceObj.load(url,function(){
	    if(callBack != null && callBack != undefined){
		    callBack();
		    
	    }
    });
    unblock();
  }
  
  //解除加载等待
function unblock(){
  window.setTimeout(function(){
	  $.unblockUI();
  },1000);
}
//判断obj是否为空,true代表是，false代表否
function isEmpty(obj){
   if(obj == null || obj == "" || obj == undefined){
      return true;
   }
   return false;
}
//给当前对象添加边框
function addBorder(curObj){
   $(curObj).css("border","2px solid #ccc");
}

//给当前对象去掉边框
function removeBorder(curObj){
   $(curObj).css("border","1px solid #ccc");
}
//呈现加载等待区域
function block(){
  $.blockUI(
            
            {
              message:"<img src='image/load.gif'/>",
              css:{
               border: "0px"
              }
            
            }
           );
}
//填充表单的方法
/**
frmId:表单id,
urlArg:表单请求路径,
method:表单请求方式，
async:表单请求是否为异步请求，false表示非异步请求，true表示异步请求,
callBack:回调函数
*/
function formFill(frmId,urlArg,method,async,callBack){
   var asyncArg = true;
   if(!async){
      asyncArg = false;
   }
   var resultArg = {};
   $.ajax({
      url: urlArg,
      type: method,
      async:asyncArg,
      success: function(result){
          var resultObj = eval("(" + result + ")");
          var content =  resultObj[0];
          if(content != null && content != undefined && content != ""){
	          var frm = $(frmId);
	          block();
	          realFormfill(frm,content);
	          unblock();
          }
          resultArg = resultObj;
      },
      error: function(request,error,msg){
         Ext.MessageBox.alert("Exception Window",$i18n("common.system.exception"));   
      }
       
   });
   if(callBack != null && callBack != undefined){
     callBack();
   }
   return resultArg;
}
var flag = 0;
//验证正数
function validatePositiveNumberForCart(curObj){
   var value = $(curObj).val();
   var id = $(curObj).attr("id");
   id = id.replace("cart","");
   var partner = /^[1-9]?[0-9]*$/gi;
   var result = partner.test(value);
   var varVal = 0;
   if(!result){
     var bakeValue = $(curObj).next("input").val();
     $(curObj).val(bakeValue);
   }else{
     var remaimCount =  findRemainGoods(id);
     var bakeValue = $(curObj).next("input").val();
     bakeValue = bakeValue == null || bakeValue == "" || bakeValue == undefined ? "0" : bakeValue;
     value = value == null || value == "" || value == undefined ? "0" : value;
     varVal = (+value) - (+bakeValue);
     if((+remaimCount) - ((+value) - (+bakeValue)) < 0){
       $(curObj).css("background-color","yellow");
       showMessage("对不起，此商品库存不足！","warn");
       $(curObj).val(bakeValue);
     }else{
	     saveGoodsCountToCart(id,value);
	     //resetDisHasSoldCount3(id,varVal);
	     //resetDisRestCount3(id,varVal);
	     reCreateGoodsCartInfo();
     }
   }

}


//将填写好的数字保存到数据库中去
function saveGoodsCountToCart(id,value){
    $.ajax({
       url:"saveGoodsCountToCart.action",
       async: false,
       data: "goodsVO.id=" + id + "&goodsVO.goodsCount=" + value,
       type:"POST",
       success: function(result){
         showSystemErrorMsg(result);
       }
    });
}
//查找商品库存
function findRemainGoods(id){
    var remainCount = 0;
    $.ajax({
       url:"findRemainGoods.action",
       async: false,
       data: "goodsVO.id=" + id,
       type:"POST",
       success: function(result){
         remainCount = result;
         showSystemErrorMsg(result);
       }
    });
    return remainCount;
}
//真正填充表单的方法
function realFormfill(obj,result){
  if(obj != null && obj != undefined){
	  var children = obj.children();
	  if(children.length == 0){
	     var name = obj.attr("name");
	     if(name != null && name != "" && name != undefined){
		     var value = eval("result" + "." + name);
		     var valueArg = obj.get(0).value;
		     var hrefArg = obj.get(0).href;
		     var innerHTMLArg = obj.get(0).innerHTML;
		     
		     if(valueArg != undefined){
			    obj.val(value);
		     }else if(hrefArg != undefined){
		       obj.attr("href",value);
		     }else if(innerHTMLArg != undefined){
			   obj.html(value);
		     }
	     }
	  }else{
	     var tempObj = {};
	     children.each(
	       function(){
	          realFormfill($(this),result);
	       }
	     );
	     
	  }
  }
}

//国际化colM
function i18nColM(colM){
  if(colM != null && colM != undefined){
     var temp = null;
     var tempKey = "";
     var tempValue = "";
     for(var i = 0; i < colM.length; i++){
        temp = colM[i];
        tempKey = temp.header;
        tempKey = tempKey == null || tempKey == undefined ? "" : tempKey;
        if(tempKey != ""){
	        tempValue = $i18n(tempKey);
	        temp.header = tempValue;
        }
     }
  }
}

/**
*根据传入的key值，来得到国际化内容
*key：传入的国际化键
*/
function $i18n(key){
  var value = "";
  $.ajax({
     type: "GET",
     url: "findValueByKey.action",
     data:"key=" + key,
     async: false,
     success: function(result){
        value = result;
     },
     error: function(){
       var errorMsg = $("#errorMsg").html();
       Ext.MessageBox.alert("Exception Window",errorMsg);    
     }
  });
  return value;
}
//显示错误提示信息
function showErrorMsg(error){
    window.location.href="error.jsp?msg=<font color=red>System Exception:<br>" + error + "</font>";
}
//显示系统异常提示信息
function showSystemErrorMsg(errorMsg){
   if(errorMsg.indexOf("SystemException") == 0){
       window.location.href="error.jsp?msg=<font color=red>" + errorMsg + "</font>";
   }
}

//将字符串格式的json数据转换为json格式的数据
function strToJson(data){
	var reCat1 = /\[|\]|{|\'/g;
    var reCat2 = /}\,|}/;
	var reCat3 = /\,/g;
	var reCat4 = /:/g;
	data = data.replace(reCat1,"");
	
	var arrData = data.split(reCat2);
	var arrData2 = null;
	var arrData3 = null;
	var arrData4 = null;
    var jsonArray = [];

	var temp = "";
	var tempObjStr = "";
	var key = "";
	var value = "";
	for (var i = 0; i < arrData.length; i++)
	{
	  var jsonObj = {};
	  temp = arrData[i];
	  arrData2 = temp.split(reCat3);
	  for(var j = 0 ; j < arrData2.length; j++){
	     tempObjStr = arrData2[j];
         arrData3 = tempObjStr.split(reCat3);
		 for(var k = 0; k < arrData3.length; k++){
           tempObjStr = arrData3[k]; 
		   arrData4 = tempObjStr.split(reCat4);
		   for(var h = 0; h < arrData4.length; h++){
		       if(h == 0){
				 key = arrData4[h];
			   }
			   if(h == 1){
				 value = arrData4[h];
				 jsonObj[key] = value;
				 
			   }
		   }

		 }
	  }
	  jsonArray[jsonArray.length] = jsonObj;
	}
	return jsonArray;
}
//设置选中的导航项
function setNaviChoosen(naviNumber){
   if(naviNumber != null && naviNumber != undefined){
      var i = 0;
      $(".navi_td").each(function(){
         if(naviNumber == i){
           $(this).attr("name","choosen");
           addNaviBackground(this);
         }else{
           $(this).attr("name","");
           reduceNaviBackground(this);
         }
         i++;
      });
   }
}

//给导航条添加背景色
function addNaviBackground(curObj){
	$(curObj).css("background-color","#ccc");
}
//给导航条去掉背景色
function reduceNaviBackground(curObj){
    var name = $(curObj).attr("name");
    if(name != "choosen"){
       $(curObj).css("background-color","");
    }
}
//点击导航条之后，给导航条添加背景色
function addNaviBackgroundAfterClick(curObj){
  $(".navi_td").each(function(){
      $(this).attr("name","");
      $(this).css("background-color","");
  });
  $(curObj).attr("name","choosen");
  $(curObj).css("background-color","#ccc");
}
//得到当前系统语言
function getCurPageLanguage(){
  var curLanguage = "";
  $.ajax({
     url: "findCurLanguge.action",
     async: false,
     success: function(result){
        curLanguage = result;
     },
     error: function(request,error,status){
         showErrorMsg(error);
     }
  });
  return curLanguage;
}

//一弹出框中购物车中的内容
function removeSelf(curObj){
        $(curObj).remove();
        load("contentDiv","disGoods.html",false,null);
}


//打开购物车弹出框
var goodsDatas = [];
function openGoodsCartDialog(goodsCartDiv,goodsId){
   var curUserName = getCurUserName();
   curUserName = curUserName == 'null'? null : curUserName;
   if(curUserName != "" && curUserName != undefined && curUserName != null){
           var remaimCount =  findRemainGoods(goodsId);
		   remaimCount = remaimCount == null || remaimCount == undefined || remaimCount == "" ? 0 : remaimCount;
		   if((+remaimCount) - 1 < 0){
		     showMessage("对不起，此商品库存不足！","warn");
		     return;
		   }
   }else{
      createLoginInterface();
      return;
   }
   
   var curLanguage = getCurPageLanguage();
  
   if(curLanguage == "CN"){
     $("#" + goodsCartDiv).dialog({
	     width: '820',
	     height: '620',
	     modal: false,
	     beforeClose: function(event,ui){renewUrl("findGoods.action");removeSelf(this);return true;},
	     buttons: {'立即购买': function(){goToBuyAtOnce(this);}}
     });
   }else{
      $("#" + goodsCartDiv).dialog({
	     width: '820',
	     height: '600',
	     beforeClose: function(event,ui){renewUrl("findGoods.action");removeSelf(this);return true;},
	     buttons: {'Buy Now': function(){alert("还在开发中");removeSelf(this);}}
     });
   }
  addGoodsToCart(goodsId);
  goodsData = findSingleGoods(goodsId)[0];
  
  //resetDisRestCount(goodsId);
  //resetDisHasSoldCount(goodsId);
  createGoodsCartInfo();
  $("#goodsCartDiv").css("height","500px");
}
//立即购买
function goToBuyAtOnce(curObj){
   $(curObj).dialog("close");
   load("contentDiv","order.html",false,function(){
      createOrderMenuDiv();
   });
}

//重新设置剩余商品数量
function resetDisRestCount(goodsId){
   var restCountDiv = $("#restCount" + goodsId);
   var restCount = restCountDiv.html();
   restCount = (+restCount) - 1;
   restCountDiv.html(restCount);
}


//重新设置已经卖出商品数量
function resetDisHasSoldCount(goodsId){
   var hasSoldCountDiv = $("#hasSoldCount" + goodsId);
   var restCount = hasSoldCountDiv.html();
   restCount = (+restCount) + 1;
   hasSoldCountDiv.html(restCount);
}


//重新设置剩余商品数量
function resetDisRestCount2(goodsId){
   var restCountDiv = $("#restCount" + goodsId);
   var restCount = restCountDiv.html();
   restCount = (+restCount) + 1;
   restCountDiv.html(restCount);
}


//重新设置已经卖出商品数量
function resetDisHasSoldCount2(goodsId){
   var hasSoldCountDiv = $("#hasSoldCount" + goodsId);
   var restCount = hasSoldCountDiv.html();
   restCount = (+restCount) - 1;
   hasSoldCountDiv.html(restCount);
}


//重新设置剩余商品数量
function resetDisRestCount3(goodsId,value){
   var restCountDiv = $("#restCount" + goodsId);
   var restCount = restCountDiv.html();
   restCount = (+restCount) - (+value);
   restCountDiv.html(restCount);
}


//重新设置已经卖出商品数量
function resetDisHasSoldCount3(goodsId,value){
   var hasSoldCountDiv = $("#hasSoldCount" + goodsId);
   var restCount = hasSoldCountDiv.html();
   restCount = (+restCount) + (+value);
   hasSoldCountDiv.html(restCount);
}




//将商品放入购物车库中
function addGoodsToCart(goodsId){
   $.ajax({
      type:"POST",
      url:"addGoodsToCart.action",
      data:"goodsVO.id=" + goodsId,
      success: function(result){
        
      }
   });
}

//根据id查询产品信息
function findSingleGoods(goodsId){
   var goodsData = null;
   $.ajax({
      type: "POST",
      url: "findSingleGoods.action",
      data: "goodsVO.id=" + goodsId,
      async: false,
      success: function(result){
         goodsData = strToJson(result);
         showSystemErrorMsg(result);
      }
   });
   return goodsData;
}

//创建购物车信息
function createGoodsCartInfo(){
  block();
  $("#goodsCartTable").html("");
  setGoodsDatas(goodsData);
  var columns = [
       new Ext.grid.RowNumberer(),
      {header:"goodsId",dataIndex:"id",hidden: true,renderer:renderGoodsId},
      {header:"cms.td.header.goodsPic",dataIndex:"goodsPic",renderer:renderGoodsPic,width:120,align:"center"},
      {header:"cms.td.header.goodsName",dataIndex:"goodsName",renderer:renderGoodsName,align:"center"},
      {header:"cms.td.header.goodsRestCount1",dataIndex:"goodsRestCount",renderer:renderGoodsRestCount,width: 120,align:"center"},
      {header:"cms.td.header.goodsPrice",dataIndex:"goodsPrice",width: 80,renderer:renderGoodsPriceForCart,align:"center"},
      {header:"cms.td.header.unit",dataIndex:"goodsPriceUnit",width:40,sortable: false,renderer:renderUnit,align:"center"},
    
      {header:"cms.td.header.goodsBuyCount",dataIndex:"goodsCount",width:80,renderer:renderGoodsCartCountForCart,align:"center"},
      {header:"cms.td.header.increaseOrReduce",dataIndex:"operation",width:80,renderer:renderIncreaseOrReduce,align:"center"},
      {header:"cms.td.header.totalPrice",dataIndex:"totalPrice",width:80,renderer:renderTotalPrice,align:"center"},
      {header:"cms.td.header.operation",dataIndex:"deleteOperation",width:80,renderer:renderDeleteOperation,width: 60,align:"center"}
      
  ];
   i18nColM(columns);
   var title = $i18n("cms.label.goodsCart.title");
   var colM = new Ext.grid.ColumnModel(columns);
   var tableObj = {};
   tableObj.height = 400;
   tableObj.width = 600;
   tableObj.colM = colM;
   tableObj.fields = ["id","goodsPic","goodsName","goodsRestCount","goodsPrice","goodsPriceUnit","goodsCount","operation","totalPrice","deleteOperation"];
   tableObj.gridId = "goodsCartTable";
   tableObj.title = title;
   tableObj.pageSize = 3;
   tableObj.disPageId = 'cartDisPageId';
   $.splitPage(tableObj,"findGoodsFromCart.action");
   caculateTotalPrice();
   unblock();
}

//渲染产品名称数量
function renderGoodsCartCountForCart(value,cellMeta,record){
   var id = record.data["id"];
   return "<div style='height: 100;vertical-align: bottom;padding-top: 40px'><input id='cart" + id + "'onclick='$(this).focus()' onchange='validatePositiveNumberForCart(this)' style='width:60px' type='text' value='" + value + "'/><input  type='hidden' value='" + value + "'/></div>";
}


//渲染产品名称
function renderGoodsPriceForCart(value,cellMeta,record){
   var id = record.data["id"];
   return "<div style='height: 100;vertical-align: bottom;padding-top: 40px' id='cart" + id + "'>" + value + "</div>";
}

//渲染产品名称
function renderGoodsRestCount(value,cellMeta,record){
   return "<div style='height: 100;vertical-align: bottom;padding-top: 40px'>" + value + "</div>";
}

//渲染产品名称
function renderGoodsId(value,cellMeta,record){
   return "<div class='goodsId'>" + value + "</div>";
}

//渲染新增按钮、递减按钮
function renderIncreaseOrReduce(value,cellMeta,record){
   var id = record.data["id"];
   return "<div style='height: 100;vertical-align: bottom;padding-top: 40px'><img onclick='addGoodsToCartOneByOne(this);' onmouseover='makeBigImage(this,20,25);' onmouseout='makeBigImage(this,15,25);' title='新增' class='increaseOrReduce' src='image/increase.JPG' width='15px' height='25px' id='" + id + "'/><img onclick='reduceGoodsFromCartOneByOne(this);' onmouseover='makeBigImage(this,20,25);' onmouseout='makeBigImage(this,15,25);'  class='increaseOrReduce' src='image/reduce.JPG' title='减少' width='15px' height='25px' id='" + id + "'/></div>";
}
//逐个增添商品到购物车库
function addGoodsToCartOneByOne(curObj){
   var goodsId = $(curObj).attr("id");
   var curRemainCount = findRemainGoods(goodsId);
   curRemainCount = curRemainCount == null || curRemainCount == undefined || curRemainCount == "" ? 0 : curRemainCount;
   var reaminCount = (+curRemainCount) - 1;
   if(reaminCount < 0){
     showMessage("对不起，此商品库存不足！","warn");
     return;
   }
   addGoodsToCart(goodsId);
   //resetDisRestCount(goodsId);
   //resetDisHasSoldCount(goodsId);
   reCreateGoodsCartInfo();
}
//重新创建购物车
function reCreateGoodsCartInfo(){
   $("#goodsCartTable").html("");
   createGoodsCartInfo();
}
//逐个从购物车中减少商品
function reduceGoodsFromCartOneByOne(curObj){
   var goodsNo = $(curObj).attr("id");
   $.ajax({
      url:"reduceGoodsFromCartOneByOne.action",
      type: "GET",
      data: "goodsVO.id=" + goodsNo,
      async: true,
      success: function(result){
          //resetDisRestCount2(goodsNo);
          //resetDisHasSoldCount2(goodsNo);
          reCreateGoodsCartInfo();
          showSystemErrorMsg(result);
      }
   });
}


//渲染产品名称
function renderTotalPrice(value,cellMeta,record){
   var id = record.data["id"];
   return "<div style='height: 100;vertical-align: bottom;padding-top: 40px' id='price" + id + "'>" + value + "</div>";
}

//计算合计
function caculateTotalPrice(){
   $.ajax({
      url: "caculateTotalPrice.action",
      type: "GET",
      async: true,
      success: function(result){
          $("#totalAmount").html(result);
          showSystemErrorMsg(result);
      }
   });

}


//渲染删除操作
function renderDeleteOperation(value,cellMeta,record){
   var id = record.data["id"];
   return "<div style='height: 100;vertical-align: bottom;padding-top: 25px'><img onclick='deleteGoodsFromCart(this);' title='删除' class='deleteOperation' src='image/delete.bmp' id='" + id + "'/></div>";
}

//从购物车库中删除指定的商品
function deleteGoodsFromCart(curObj){
  var goodsNo = $(curObj).attr("id");
  $.ajax({
     type:"GET",
     url:"deleteGoodsFromCart.action",
     data:"goodsVO.id=" + goodsNo,
     async:true,
     success: function(result){
       reCreateGoodsCartInfo();
       showSystemErrorMsg(result);
     }
  });
}

//使得图标/图片变大
function makeBigImage(imgObj,width,height){
   $(imgObj).attr("width",width);
   $(imgObj).attr("height",height);
}
//设置商品信息，这些设置的商品信息为加入购物车的商品信息
function setGoodsDatas(goodsData){
   goodsData.count = 1;
   var length = goodsDatas.length;
   if(length == 0){
     goodsDatas[goodsDatas.length] = goodsData;
   }else{
     var addDataFlag = true; 
     var curGoodsId = goodsData.goodsId;
     var tempGoodsId = "";
     $.each(goodsDatas,function(index,contentObj){
        tempGoodsId = contentObj.goodsId;
        tempGoodsId = tempGoodsId == null || tempGoodsId == undefined ? "" : tempGoodsId;
        if(tempGoodsId != "" && tempGoodsId == curGoodsId){
           addDataFlag = false;
           contentObj.count += 1; 
        }
     });
     if(addDataFlag){
        goodsDatas[goodsDatas.length] = goodsData;
     }
     
   }
}
//得到当前登陆用户账号
function getCurUserName(){
  var userName = "";
  $.ajax({
     type:"POST",
     async: false,
     url: 'getCurUserName.action',
     success: function(result){
       userName = result;
       userName = userName == null ? "" : userName;
       //showErrorMsg(result);
     }
  });
  return userName;
}

//显示提示信息
function showMessage(message,messageLevel){
   //buttons的配置：
   //Ext.Msg.OKCANCEL, 
   //Ext.Msg.CAMCEL, 
   //Ext.Msg.YESNO,  
   //Ext.Msg.YESNOCANCEL 
   var warnLevel = Ext.MessageBox.INFO;
   if(messageLevel == 'warn'){
      warnLevel = Ext.MessageBox.WARNING;
   }else if(messageLevel == 'question'){
      warnLevel = Ext.MessageBox.QUESTION;
   }else if(messageLevel == 'error'){
     warnLevel = Ext.MessageBox.ERROR;
   }else if(messageLevel == 'info'){
     warnLevel = Ext.MessageBox.INFO;
   }
   
   Ext.MessageBox.show({
      title: "信息提示",
      width: 300,
      height: 300,
      msg:message,
      closable: true,
      buttons: Ext.Msg.OK,
      icon:warnLevel
   });
}
//将grid中td内容设置成居中显示
function setTdToVerticalAlign(){
window.setTimeout(function(){
  $(".x-grid3-row-table").find("td").each(function(){
      $(this).css("vertical-align","middle");
  });
},100);
  
}





</script>